<template>
	<view style="padding: 10px;">
		<u-input type="password" border="surround" placeholder="请输入您的旧密码" v-model="oldPassword" clearable />
		<u-input type="password" border="surround" placeholder="请输入您的新密码" v-model="newPassword" clearable />
		<u-input type="password" border="surround" placeholder="请再次输入您的新密码" v-model="agnpassword" clearable />
		<view style="margin-top: 10px;">
			<u-button text="修改" color="linear-gradient(to right, rgb(66, 83, 216), rgb(213, 51, 186))" @click="upPass">
			</u-button>
		</view>
	</view>
</template>

<script>
	import {
		upPassword
	} from '@/config/api.js'
	export default {
		data() {
			return {
				oldPassword: '',
				newPassword: '',
				agnpassword: '',
			}
		},
		methods: {
			upPass() {
				if (this.oldPassword == '' || this.newPassword == '' || this.agnpassword == '') {
					uni.$u.toast("输入内容不能为空")
				} else {
					if (this.newPassword != this.agnpassword) {
						uni.$u.toast("两次输入的新密码不一致")
					} else {
						let name = '';
						uni.getStorage({
							key: 'user_name',
							success: function(res) {
								name = res.data
							}
						})
						upPassword({}, {
							params: {
								name: name,
								oldPass: this.oldPassword,
								newPass: this.newPassword,
							}
						}).then(res => {
							uni.$u.toast("修改成功,请您重新登录")
							uni.setStorage({
								key: 'user_token',
								data: '',
								success: function() {
									console.log('清除缓存token')
								}
							});
							uni.setStorage({
								key: 'user_name',
								data: '',
								success: function() {
									console.log("清空缓存的用户名")
								}
							});
							uni.setStorage({
								key: 'is_login',
								data: 'no',
								success: function() {
									console.log("设计登录接口为no");
								}
							});
							setTimeout(() => {
								uni.reLaunch({
									url: '../../login/login'
								})
								/* 	uni.redirectTo({
										url: '../../login/login'
									}) */
							}, 500)
						}).catch((e) => {
							console.log(e);
						})
					}
				}


			}
		}
	}
</script>

<style>

</style>
